# -*- coding: utf-8 -*-
# @Time : 2019/1/11 9:27
# @Author : Administrator
# @File : employment.py
# @Project : python
# @title : 接口测试 -- 就业管理

import unittest,re,ddt
from random import random
from woniuboss_interface.util.read_data import Read_Excel
from woniuboss_interface.common.login_decode import Login


data_li = Read_Excel()
ses,host,excel_path = Login()
@ddt.ddt
class Employment(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("就业管理测试开始")
        ses.post(url = host+"/log/userLogin",
                data = {"userName":"wncd000","userPass":"woniu123","checkcode":"0000"})
        unpass = ses.post(host+"/interview/queryUnpass",data = {"pageSize":10,"pageIndex":1})  ## 未通过
        pass1 = ses.post(host+"/interview/queryPass",data = {"pageSize":10,"pageIndex":1})
        all = ses.post(url=host+"/interview/queryStuByInfo",
                          data={"pageSize":"10","pageIndex":"1","stuName":"","stuNo":"","stuClass":"全部","orientation":"全部"})   ## 查找所有的student_id
        company = ses.post(host+"/enterprise/companySearch?companyName=",
                               data={"pageSize":10,"pageIndex":1})
        cls.unpass = re.findall(r'"student_id":(.*?),',unpass.text,re.M)  ## 使用正则截取student——id,返回的是一个列表,未通过的学生id
        cls.pass1 = re.findall(r'"student_id":(.*?),',pass1.text,re.M)  ## 通过的学生id
        cls.all = re.findall(r'"student_id":(.*?),',all.text,re.M)      ## 就业管理学生id
        cls.all = re.findall(r'"enterprise_id":(.*?),"',company.text,re.M)  ## 企业id    尝试：（利用数据库去查id）
        # print(unpass,pass1,all,company)
        # print(cls.unpass,cls.pass1,cls.all,cls.all)

    @classmethod
    def tearDownClass(cls):
        print("就业管理测试完成")

    @ddt.data(*data_li.excel(excel_path,2))
    def test_unpass(self,data1):   # 技术面试未通过的操作
        index = int(random()*len(self.unpass))
        try:
            id = self.unpass[index]  ## 随机生成一个未通过的学生id
            ispass = "通过"#"%e9%80%9a%e8%bf%87"   ## 技术面试改为通过
            url = host+"/interview/insertSrecord?ispass="+ispass+"&sr.skillrecord_student_id="+id+"&sr.questions="+data1['questions']+"&sr.valuate="+data1['valuate']
            s = self.ses.get(url)
            # print(s.text)
            response = self.ses.post(host+"/interview/queryPass",data = {"pageSize":10,"pageIndex":1})
            # print(response.text)
            assert id in response.text
        except:
            print("——没有操作对象id——请预埋数据")
    #
    def test_pass(self):     # 技术面试通过的状态,不能进行操作
        ispass = "%e6%9c%aa%e9%80%9a%e8%bf%87"   ## 通过
        url = host+"/interview/insertSrecord?ispass="+ispass+"&sr.skillrecord_student_id=&sr.questions=vvvvv&sr.valuate=bbbbb"
        response = ses.get(url)
        assert "error" in response.text
    # #
    @ddt.data(*data_li.excel(excel_path,2))
    def test_simulation(self,data):     #模拟面试
        try:
            index = int(random()*len(self.all))
            data1 = "m.minterview_student_id="+self.all[index]+"&m.intent_salary="+str(data["salary"])+"&m.comm="+data["comn"]+"&m.remark="+data["remark"]
            response = ses.get(host+"/interview/insertMrecord?"+data1)
            self.assertIn(data["expect"],response.text)
        except:
            print("——没有操作对象id——请预埋数据")
    #
    @ddt.data(*data_li.excel(excel_path,2))
    def test_reality(self,data):     #真实面试
        try:
            index = int(random()*len(self.all))
            index1 = int(random()*len(self.company))
            response = ses.post(host+"/interview/insertRrecord",
                          data = {"rea.rinterview_student_id":self.all[index],"rea.rinterview_ent_id":self.company[index1],"rea.interview_post":data["interview_post"],"rea.rinterview_time":data["time"],"rea.remark":data["remark"]})
            self.assertIn(data["expect"],response)
        except:
            print("——没有操作对象id——请预埋数据")
    #
    @ddt.data(*data_li.excel(excel_path,2))
    def test_entry(self,data):     #入职情况
        # print(data)
        try:
            index = int(random()*len(self.all))
            index1 = int(random()*len(self.company))
            response = ses.post(host+"/interview/insertJobRegist",
                          data={"jr.job_student_id":self.all[index],"&jr.ent_name":self.company[index1],"jr.job_position":data["interview_post"],"jr.job_time":data["time"],"jr.job_salary":str(data["salary"]),"jr.remark":data["remark"]})
            self.assertIn(data["expect"],response)
        except:
            print("——没有操作对象id——请预埋数据")

    @ddt.data(*data_li.excel(excel_path,2))
    def test_present(self,data):     #提交
        # print(self.all)
        try:
            index = int(random()*len(self.all))
            url = host+"/interview/checkOther?reCompu="+str(data["reCompu"])+"&isSign="+str(data["isSign"])+"&isHired="+str(data["isHired"])+"&stuId="+self.all[index]
            response = ses.get(url)
            self.assertIn(data["present_expect"],response)
        except:
            print("——没有操作对象id——请预埋数据")


if __name__ == '__main__':
    unittest.main()